//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//

import template from "./detailsTemplate";
const { render, staticRenderFns } = template;

export default {
  render,
  staticRenderFns,
  data() {
    return {
      allGainList: [], //红包数据
      page: 1,
      pullUpLoad: true,
      pullDownRefresh: true,
      pullTxt: "松开立即加载更多",
      loadingHttp: false,
    };
  },
  created() {
    this.redpacketId = this.$route.query.redpacketId;
    this._getRedDetails();
  },
  mounted() {},
  methods: {
    removePic() {
      this.gainRedpacket.redpacket_pic = "";
    },
    removeImg(index) {
      this.allGainList[index].user_pic = "";
    },
    _getRedDetails() {
      var params = {
        token: localStorage.getItem("token"),
        redpacket_id: this.redpacketId,
      };
      this.$vux.loading.show();
      this.$http
        .post(this.urlRequest + "?m=api&c=redpacket&a=gainRedpacket", params)
        .then((res) => {
          this.$vux.loading.hide();
          if (res.status == 0) {
            this.loadingHttp = true;
            this.gainRedpacket = res;
            this.allGainList = res.all_gain_list;
            console.log(this.allGainList);
          } else {
            if (res.ret_msg && res.ret_msg != "") {
              this.$vux.toast.show({
                text: res.ret_msg,
              });
            }
          }
        })
        .catch((error) => {
          this.$vux.loading.hide();
          this.$vux.toast.show({
            text: "数据请求超时",
          });
        });
    },
    _getRedDetailsMore(flag) {
      var params = {
        token: localStorage.getItem("token"),
        redpacket_id: this.redpacketId,
        page: this.page,
      };
      if (flag) {
        this.$vux.loading.show();
      }
      this.$http
        .post(
          this.urlRequest + "?m=api&c=redpacket&a=currentRedpacketList",
          params
        )
        .then((res) => {
          if (flag) {
            this.$vux.loading.hide();
          }
          if (res.status == 0) {
            if (this.page == 1) {
              this.allGainList = res.gain_list;
            } else {
              this.allGainList = this.allGainList.concat(res.gain_list);
            }
            if (res.gain_list.length < 10) {
              this.pullUpLoadFalg = true;
            }
          } else {
            if (res.ret_msg && res.ret_msg != "") {
              this.$vux.toast.show({
                text: res.ret_msg,
              });
            }
          }
        })
        .catch((error) => {
          this.$refs.scroll.forceUpdate(false);
          this.pullUpLoad = false;
          this.$vux.loading.hide();
          this.$vux.toast.show({
            text: "数据请求超时",
          });
        });
    },
    pullingDown() {
      this.page = 1;
      this._getRedDetailsMore(0);
    },
    pullingUp() {
      if (!this.allGainList) {
        return false;
      }
      if (this.pullUpLoadFalg) {
        this.$refs.scroll.forceUpdate(false);
        return false;
      }
      this.page += 1;
      this._getRedDetailsMore(0);
    },
  },
};

// WEBPACK FOOTER //
// ./src/components/redPacket/details.vue
